<!--菜单管理-->
<template>
    <div class="minW1060-auto bg-fff mt10">
        <div class="pad20">
            <el-row class="text-left">
                <div class="dlblock-mb20">
                    <span class="pr5">&ensp;&ensp;&ensp;菜单名称</span>
                    <el-input
                            style="width: 180px"
                            placeholder="请输入内容"
                            v-model="menuName"
                            maxlength="10"
                            clearable>
                    </el-input>
                </div>
                <div class="dlblock-mb20 pr5 pl5">
                    <el-button class="el-icon-search ml5" circle @click="getData()"></el-button>
                </div>
                <div class="dlblock-mb20 pr5 pl5">
                    <el-button type="primary" @click="editBtn(1)">添加</el-button>
                </div>
            </el-row>
            <!--表格区域-->
            <el-row>
                <el-table
                        class="my-table"
                        :data="tableData" stripe
                        v-loading="loading"
                        :header-row-class-name="'my-table-header'"
                        @selection-change="handleSelectionChange"
                        ref="myTable"
                        border>
                    <el-table-column align="center" prop="ids" label="序号" type="index" width="80"></el-table-column>
                    <el-table-column align="center" prop="name" label="菜单名称"></el-table-column>
                    <el-table-column align="center" prop="parentName" label="父级菜单"></el-table-column>
                    <el-table-column align="center" prop="url" label="url"></el-table-column>
                    <el-table-column align="center" prop="icon" label="icon"></el-table-column>
                    <el-table-column align="center" label="操作" fixed="right">
                        <template slot-scope="{row}">
                            <el-button type="text" @click="editBtn(2,row)">编辑</el-button>
                            <el-button type="text" style="color: #f56c6c" @click="editBtn(3,row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="my-pagination">
                    <el-pagination background layout="total, prev, pager, next" :total="pages.total"
                                   :current-page="pages.page" @current-change="pageChange"></el-pagination>
                </div>
            </el-row>
        </div>
    </div>
</template>

<script>
    import {delRoute,getMenu} from '@/api';

    export default {
        name: "index1",
        data() {
            return {
                menuName: null,
                tableData: [],
                tableSelection: [],
                loading: false,
                pages: {
                    page: 1,
                    total: 0,
                    size: 15
                },
            }
        },

        methods: {

            /**
             * 获取表格数据
             */
            getData() {
                this.loading = true
                getMenu({
                    pageNum: this.pages.page,
                    name: this.menuName,
                }).then(res => {
                    if (res != null && res.code == 200) {
                        this.tableData = res.data.list;
                        this.pages.total = res.data.count;
                    }
                    console.log(res)
                }).finally(
                    this.loading = false
                )
            },

            editBtn(t,row){
                if (t==1){
                    this.$message.success("添加菜单请联系管理员")
                }else if(t==2){
                    this.$message.success("编辑菜单请联系管理员")
                }else {
                    this.$message.success("删除菜单请联系管理员")
                }
            },

            /**
             * 分页切换
             * @param val
             */
            pageChange(val) {
                this.pages.page = val;
                this.getData();
            },

            /**
             * 删除单条线路
             * @param row
             */
            delOne(row) {
                this.$confirm('此操作将永久删除该设备, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    delRoute({id: row.routeId}).then(res => {
                        if (res.code == 200) {
                            this.$message({type: 'success', message: '删除成功'});
                            this.getData()
                        } else {
                            this.$message({type: 'error', message: '删除失败'});
                        }
                    })
                }).catch(() => {
                    this.$message({type: 'info', message: '已取消删除'});
                });
            },

            handleSelectionChange(val) {
                this.tableSelection = val;
            },

        },

        mounted() {
            this.getData()
        }

    }
</script>

<style scoped>
    .my-table /deep/ tr, .my-table /deep/ td{
        padding: 0 !important;
        height: 35px;
        line-height: 35px;
    }
</style>
